﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using ChatForum.Domain;

namespace ChatForum.DataContract
{
    [DataContract(Name = "Post")]
    [KnownType(typeof(ThreadDTO))]
    public class PostDTO
    {
        public PostDTO(Post post)
		{
			if (post == null)
				throw new ArgumentNullException("post");

            this.Title = post.Title;
            this.Description = post.Description;
            this.ParentPost = post.ParentPost;
            this.ParentCategory = post.ParentCategory;
            this.Rating = post.Rating;
            this.ID = post.ID;
            this.CreatedDate = post.CreatedDate;
            this.CreatedBy = post.CreatedBy;
            this.ModifiedDate = post.ModifiedDate;
            this.ModifiedBy = post.ModifiedBy;
        }
        public Post Convert()
        {
            return new Post()
            {
                Title = this.Title,
                Description = this.Description,
                ParentPost = this.ParentPost,
                ParentCategory = this.ParentCategory,
                Rating = this.Rating,
                ID = this.ID,
                CreatedDate = this.CreatedDate,
                CreatedBy = this.CreatedBy,
                ModifiedDate = this.ModifiedDate,
                ModifiedBy = this.ModifiedBy,
            };
        }

        [DataMember]
        public string Title { get; set; }
        [DataMember]
        public string Description { get; set; }
        [DataMember]
        public Guid ParentPost { get; set; }
        [DataMember]
        public Guid ParentCategory { get; set; }
        [DataMember]
        public int Rating { get; set; }


        [DataMember]
        public Guid ID { get; set; }
        [DataMember]
        public DateTime CreatedDate { get; set; }
        [DataMember]
        public string CreatedBy { get; set; }
        [DataMember]
        public DateTime ModifiedDate { get; set; }
        [DataMember]
        public string ModifiedBy { get; set; }
    }
}
